{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# extract audio feature"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 01 test sample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import os\n",
    "# import csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# path = '../data/raw/IEMOCAP_full_release/Session1/sentences/wav/Ses01F_impro01/'\n",
    "# file_name = path + 'Ses01F_impro01_F002.wav'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# out_file = '../data/processed/IEMOCAP/test.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# cmd = 'SMILExtract -C /home/dato/program/opensmile-2.3.0/config/modified_prosodyShsViterbiLoudness.conf -I ' + file_name + ' -O ' + out_file + ' -headercsv 1'\n",
    "\n",
    "# cmd = 'SMILExtract -C /home/dato/program/opensmile-2.3.0/config/modified_MFCC12_E_D_A_Z.conf -I ' + file_name + ' -O ' + out_file  + ' -headercsv 1'\n",
    "# cmd = 'SMILExtract -C /home/dato/program/opensmile-2.3.0/config/modified_MFCC12_E_D_A.conf -I ' + file_name + ' -csvoutput ' + out_file  + ' -headercsv 0' # MFCC12EDA case\n",
    "\n",
    "# cmd = 'SMILExtract -C /home/dato/program/opensmile-2.3.0/config/modified_emobase2010.conf -I ' + file_name + ' -csvoutput ' + out_file  + ' -headercsv 1'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print cmd\n",
    "# os.system(cmd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# lines = []\n",
    "# with open('../data/processed/IEMOCAP/processeed_prosody.csv') as f:\n",
    "#     csv_reader = csv.reader(f)\n",
    "#     lines = [x for x in csv_reader]        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 01 extract MFCC / prosody / emobase feature from multiple files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import csv\n",
    "from file_util import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### select opensmile configuration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 01-1 MFCC EDA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'../data/processed/IEMOCAP/MFCC12EDA.csv'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# MFCC E D A Z\n",
    "# OPENSMILE_CONFIG_PATH = '/home/dato/program/opensmile-2.3.0/config/modified_MFCC12_E_D_A_Z.conf'   # normalized \n",
    "# out_file = '../data/processed/IEMOCAP/MFCC12EDAZ.csv'\n",
    "    \n",
    "    \n",
    "# MFCC E D A    \n",
    "OPENSMILE_CONFIG_PATH = '/home/dato/program/opensmile-2.3.0/config/modified_MFCC12_E_D_A.conf'    \n",
    "out_file = '../data/processed/IEMOCAP/MFCC12EDA.csv'\n",
    "    \n",
    "out_file    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def extract_feature( list_in_file, out_file ) :\n",
    "    print out_file\n",
    "    \n",
    "    cnt = 0    \n",
    "    for in_file in list_in_file:        \n",
    "#         cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -O ' + out_file + ' -headercsv 0'  #MFCC12EDAZ, prosody\n",
    "        cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -csvoutput ' + out_file + ' -headercsv 0'   # MFCC12EDA\n",
    "#         cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -csvoutput ' + out_file + ' -headercsv 0'   # emobase2010\n",
    "        os.system(cmd)\n",
    "        \n",
    "        cnt += 1\n",
    "        if cnt % 1000 == 0:\n",
    "            print str(cnt) + \" / \" + str( len(list_in_file) )\n",
    "            sys.stdout.flush()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Session1, #sum files: 1819\n",
      "Session2, #sum files: 3630\n",
      "Session3, #sum files: 5766\n",
      "Session4, #sum files: 7869\n",
      "Session5, #sum files: 10039\n",
      "../data/processed/IEMOCAP/MFCC12EDA.csv\n",
      "1000 / 10039\n",
      "2000 / 10039\n",
      "3000 / 10039\n",
      "4000 / 10039\n",
      "5000 / 10039\n",
      "6000 / 10039\n",
      "7000 / 10039\n",
      "8000 / 10039\n",
      "9000 / 10039\n",
      "10000 / 10039\n"
     ]
    }
   ],
   "source": [
    "# [schema] ID, transcriptions [csv]\n",
    "\n",
    "list_files = []\n",
    "\n",
    "for x in xrange(5):\n",
    "    sess_name = 'Session' + str(x+1)\n",
    "    path = '../data/raw/IEMOCAP_full_release/' + sess_name + '/sentences/wav/'\n",
    "    file_search(path, list_files)\n",
    "    list_files = sorted(list_files)\n",
    "\n",
    "    print sess_name + \", #sum files: \" + str(len(list_files))\n",
    "\n",
    "extract_feature( list_files, out_file )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4457391"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with open('../data/processed/IEMOCAP/MFCC12EDA.csv') as f:\n",
    "    data = f.readlines()\n",
    "len(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"'unknown';0.000000;-6.109069e+00;-1.402484e+01;6.732327e+00;-2.546580e+01;6.154059e+00;-1.788557e+01;7.608350e+00;-2.189162e+01;-2.357424e+00;3.110782e+00;1.537108e+01;2.076875e+00;1.549505e+01;9.102157e-01;-1.072150e+00;1.679795e+00;1.134924e+00;-1.113729e+00;-1.536331e+00;-3.516938e-01;2.706552e+00;2.835383e+00;-4.857984e-01;-2.045343e+00;-4.918585e+00;1.934452e-02;1.112185e-01;4.612769e-01;-4.294967e-01;2.867506e-01;4.323770e-01;7.239794e-01;8.828823e-01;6.933632e-02;1.803990e-01;-5.409565e-01;-2.570946e-01;4.309415e-01;-2.529488e-02\\n\""
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 01-2 prosody"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'../data/processed/IEMOCAP/prosody.csv'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# prosody\n",
    "OPENSMILE_CONFIG_PATH = '/home/dato/program/opensmile-2.3.0/config/modified_prosodyShsViterbiLoudness.conf'\n",
    "out_file = '../data/processed/IEMOCAP/prosody.csv'\n",
    "    \n",
    "out_file    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def extract_feature( list_in_file, out_file ) :\n",
    "    print out_file\n",
    "    \n",
    "    cnt = 0    \n",
    "    for in_file in list_in_file:        \n",
    "        cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -O ' + out_file + ' -headercsv 0'  #MFCC12EDAZ, prosody\n",
    "#         cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -csvoutput ' + out_file + ' -headercsv 0'   # MFCC12EDA\n",
    "#         cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -csvoutput ' + out_file + ' -headercsv 0'   # emobase2010\n",
    "        os.system(cmd)\n",
    "        \n",
    "        cnt += 1\n",
    "        if cnt % 1000 == 0:\n",
    "            print str(cnt) + \" / \" + str( len(list_in_file) )\n",
    "            sys.stdout.flush()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Session1, #sum files: 1819\n",
      "Session2, #sum files: 3630\n",
      "Session3, #sum files: 5766\n",
      "Session4, #sum files: 7869\n",
      "Session5, #sum files: 10039\n",
      "../data/processed/IEMOCAP/prosody.csv\n",
      "1000 / 10039\n",
      "2000 / 10039\n",
      "3000 / 10039\n",
      "4000 / 10039\n",
      "5000 / 10039\n",
      "6000 / 10039\n",
      "7000 / 10039\n",
      "8000 / 10039\n",
      "9000 / 10039\n",
      "10000 / 10039\n"
     ]
    }
   ],
   "source": [
    "# [schema] ID, transcriptions [csv]\n",
    "\n",
    "list_files = []\n",
    "\n",
    "for x in xrange(5):\n",
    "    sess_name = 'Session' + str(x+1)\n",
    "    path = '../data/raw/IEMOCAP_full_release/' + sess_name + '/sentences/wav/'\n",
    "    file_search(path, list_files)\n",
    "    list_files = sorted(list_files)\n",
    "\n",
    "    print sess_name + \", #sum files: \" + str(len(list_files))\n",
    "\n",
    "extract_feature( list_files, out_file )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "### 01-3 emobase"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'../data/processed/IEMOCAP/emobase2010.csv'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# emobase2010\n",
    "OPENSMILE_CONFIG_PATH = '/home/dato/program/opensmile-2.3.0/config/modified_emobase2010.conf'    \n",
    "out_file = '../data/processed/IEMOCAP/emobase2010.csv'\n",
    "    \n",
    "out_file    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def extract_feature( list_in_file, out_file ) :\n",
    "    print out_file\n",
    "    \n",
    "    cnt = 0    \n",
    "    for in_file in list_in_file:        \n",
    "#         cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -O ' + out_file + ' -headercsv 0'  #MFCC12EDAZ, prosody\n",
    "#         cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -csvoutput ' + out_file + ' -headercsv 0'   # MFCC12EDA\n",
    "        cmd = 'SMILExtract -C ' + OPENSMILE_CONFIG_PATH + ' -I ' + in_file + ' -csvoutput ' + out_file + ' -headercsv 0'   # emobase2010\n",
    "        os.system(cmd)\n",
    "        \n",
    "        cnt += 1\n",
    "        if cnt % 1000 == 0:\n",
    "            print str(cnt) + \" / \" + str( len(list_in_file) )\n",
    "            sys.stdout.flush()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Session1, #sum files: 1819\n",
      "Session2, #sum files: 3630\n",
      "Session3, #sum files: 5766\n",
      "Session4, #sum files: 7869\n",
      "Session5, #sum files: 10039\n",
      "../data/processed/IEMOCAP/emobase2010.csv\n",
      "1000 / 10039\n"
     ]
    }
   ],
   "source": [
    "# [schema] ID, transcriptions [csv]\n",
    "\n",
    "list_files = []\n",
    "\n",
    "for x in xrange(5):\n",
    "    sess_name = 'Session' + str(x+1)\n",
    "    path = '../data/raw/IEMOCAP_full_release/' + sess_name + '/sentences/wav/'\n",
    "    file_search(path, list_files)\n",
    "    list_files = sorted(list_files)\n",
    "\n",
    "    print sess_name + \", #sum files: \" + str(len(list_files))\n",
    "\n",
    "extract_feature( list_files, out_file )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 02 verify"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "from file_util import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "in_file = '../data/processed/IEMOCAP/label.csv'\n",
    "label = []\n",
    "with open( in_file, 'r') as f:\n",
    "    csv_reader = csv.reader( f )\n",
    "    label = [x for x in csv_reader]\n",
    "    \n",
    "label_id = [ x[0] for x in label]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Session1, #sum files: 1819\n",
      "Session2, #sum files: 3630\n",
      "Session3, #sum files: 5766\n",
      "Session4, #sum files: 7869\n",
      "Session5, #sum files: 10039\n"
     ]
    }
   ],
   "source": [
    "list_files = []\n",
    "\n",
    "for x in xrange(5):\n",
    "    sess_name = 'Session' + str(x+1)\n",
    "    path = '../data/raw/IEMOCAP_full_release/' + sess_name + '/sentences/wav/'\n",
    "    file_search(path, list_files)\n",
    "    list_files = sorted(list_files)\n",
    "\n",
    "    print sess_name + \", #sum files: \" + str(len(list_files))\n",
    "    \n",
    "ids = [ x.split('/')[-1].split('.')[0] for x in list_files ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "for l, t in zip(label_id, ids):\n",
    "    if l != t:\n",
    "        print 'ERROR'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 03 A MFCC post-process\n",
    "- each row has MFCC feature information (41 dimesion) * audio length --> can be different according to its length\n",
    "- [0]frameIndex; [1]frameTime; were removed from processed feature\n",
    "- (10039, 750, 39)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import cPickle\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 03-A load MFCC feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "lines = []\n",
    "# with open('../data/processed/IEMOCAP/MFCC12EDAZ.csv') as f:\n",
    "with open('../data/processed/IEMOCAP/MFCC12EDA.csv') as f:\n",
    "    csv_reader = csv.reader(f)\n",
    "    lines = [x for x in csv_reader]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4457391"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(lines)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 03-B MFCC feature -> float value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "lines = [x[0] for x in lines]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "lines = [x.split(';') for x in lines]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "float_lines = [ [float(i) for i in x[1:]] for x in lines ]   # do not care the first element"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# mark the index of each chunk \n",
    "\n",
    "chunk_index = []\n",
    "for i, line in enumerate(float_lines):\n",
    "    if line[0] == 0:\n",
    "        chunk_index.append(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "no_index_float_linex = [ x[2:] for x in lines ]   # remove first two element (sequence index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# merge sequence \n",
    "\n",
    "list_MFCC = []\n",
    "\n",
    "for i in xrange( len(chunk_index) ):\n",
    "    \n",
    "    if i == len(chunk_index) -1:        # last case\n",
    "        list_MFCC.append( no_index_float_linex[ chunk_index[i]: ] )\n",
    "    else :\n",
    "        list_MFCC.append( no_index_float_linex[ chunk_index[i]:chunk_index[i+1] ] )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 03-C numpy save  7.5s cut"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "444.00747086363185\n",
      "306.4563457098706\n",
      "3412\n",
      "56\n"
     ]
    }
   ],
   "source": [
    "stat = [ len(x) for x in list_MFCC ]\n",
    "print np.mean(stat)\n",
    "print np.std(stat)\n",
    "print np.max(stat)\n",
    "print np.min(stat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# np.save('../data/processed/IEMOCAP/processed_MFCC12EDAZ_sequenceN.npy', np.asarray(stat))\n",
    "np.save('../data/processed/IEMOCAP/processed_MFCC12EDA_sequenceN.npy', np.asarray(stat))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# with open('../data/processed/IEMOCAP/processed_MFCC12EDAZ_sequenceN.txt', 'w') as f:\n",
    "with open('../data/processed/IEMOCAP/processed_MFCC12EDA_sequenceN.txt', 'w') as f:\n",
    "    for data in stat:\n",
    "        f.write( str(data) + '\\n' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10039, 750, 39)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np_MFCC = np.zeros( [10039, 750, 39], dtype=np.float)\n",
    "np.shape(np_MFCC)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in xrange( len(list_MFCC) ):\n",
    "    \n",
    "    if len( list_MFCC[i] ) > 750:\n",
    "        np_MFCC[i][:] = list_MFCC[i][:750]\n",
    "    else:\n",
    "        np_MFCC[i][:len(list_MFCC[i])] = list_MFCC[i][:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "# np.save('../data/processed/IEMOCAP/processed_MFCC12EDAZ.npy', np_MFCC)\n",
    "np.save('../data/processed/IEMOCAP/processed_MFCC12EDA.npy', np_MFCC)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 04 prosody post-process\n",
    "- [0]@name string; [36]class numeric; were removed from original feature (total 37)\n",
    "- (10039, 35) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 04-A load prosody feature  &  conver to np format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10039"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lines = []\n",
    "with open('../data/processed/IEMOCAP/prosody.csv') as f:\n",
    "    csv_reader = csv.reader(f)\n",
    "    lines = [x for x in csv_reader]\n",
    "len(lines)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10039, 35)"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np_prosody = np.zeros( [10039, 35], dtype=np.float)\n",
    "np.shape(np_prosody)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in xrange( len(np_prosody) ):\n",
    "    np_prosody[i] = lines[i][1:-1]    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 04-B  numpy save"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.save('../data/processed/IEMOCAP/processed_prosody.npy', np_prosody)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 05 emobase2010 post-process\n",
    "- [0]frameTime aws removed from original feature (total 1583)\n",
    "- (10039, 1582) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 05-A load emobase2010 feature  &  conver to np format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10039"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lines = []\n",
    "with open('../data/processed/IEMOCAP/emobase2010.csv') as f:\n",
    "    csv_reader = csv.reader(f)\n",
    "    lines = [x for x in csv_reader]\n",
    "\n",
    "lines = [x[0].split(';') for x in lines]\n",
    "lines = [ [float(t) for t in x] for x in lines]\n",
    "len(lines)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10039, 1582)"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np_emobase = np.zeros( [10039, 1582], dtype=np.float)\n",
    "np.shape(np_emobase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in xrange( len(np_emobase) ):\n",
    "    np_emobase[i] = lines[i][1:]    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 04-B  numpy save"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.save('../data/processed/IEMOCAP/processed_emobase2010.npy', np_emobase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10039, 1582)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tmp = np.load( '../data/processed/IEMOCAP/processed_emobase2010.npy')\n",
    "np.shape(tmp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:tf14_p27]",
   "language": "python",
   "name": "conda-env-tf14_p27-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
